package leetcode1;

public class Day7 {

    public static void main(String[] args) {
        String s = "IDID";
        diStringMatch(s);
    }
    //942.增减字符串匹配
    public static int[] diStringMatch(String s) {
        //i:选择当前最小值  d:选择最大值
        int n = s.length();
        int left=0,right=n-1;
        int[] ret = new int[n+1];
        int i=0;
        for(;i<n;i++) {
            if(s.charAt(i) == 'I') {
                ret[i]=left++;
            }else {
                ret[i]=right--;
            }
        }
        ret[i]=left;
        return ret;
    }
}
